import { pullAll } from 'lodash-es';
import type { Ref } from 'vue';
import { reactive } from 'vue';

interface props {
    seat: Ref<number>;
    name: Ref<string>;
}
export default function useCard(props: props): useCardReturn {
    const Card: useCardReturn = {
        h: reactive<cards>([]),
        e: reactive<cards>([]),
        j: reactive<cards>([]),
        num(area) {
            if (area.length === 1) {
                return Card[area as cardArea].length;
            }
            let sum = 0;
            for (const i of area) {
                sum += Card[i as cardArea].length;
            }
            return sum;
        },
        // cname(card) {
        //     return card[0];
        // },
        // figure(card) {
        //     return card[1];
        // },
        // pattern(card) {
        //     return card[2];
        // },
        gameDraw() {
            this.draw(4);
        },
        judge() {
            // const card = this.cardPile.value.shift();
            // return card;
        },
        draw(num = 1, position = 'top') {
            const cards = this.cardPile.value.splice(0, num);
            console.log(`${this.name}摸了${num}张牌`);
            this.gain(cards);
        },
        gain(cards) {
            Card.h.push(...cards);
        },
        discard(cards) {
            pullAll(h, cards);
            this.discardPile.push(...cards);
            console.log(`${this.name}弃置了${cards}`);
        },
        async chooseToDiscard(num) {
            console.log(`请弃置${num}张牌`);
            await this.sleep(2000);
            const cards = sampleSize(h, num);
            this.discard(cards);
            console.log('弃牌阶段结束');
        },
    };
    return Card;
}
